package com.software.levelupandroid.service;

import static android.content.Context.ALARM_SERVICE;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class WidgetBroadcastReceiver extends BroadcastReceiver  {
    private PendingIntent pi;
    private AlarmManager iAlarmManager;
    //延迟10分钟
    private static int TIME_DELAY = 600000;
    @Override
    public void onReceive(Context context, Intent intent) {
        String title = intent.getStringExtra("title");
        String content = intent.getStringExtra("content");
        String type = intent.getStringExtra("task_type");
        iAlarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE);
        String action = intent.getAction();
        if (action.equals("alarmManage")) {
            //触发延迟广播
            Intent i = new Intent(context, NotionService.class);
            i.putExtra("title",title);
            i.putExtra("content",content);
            i.putExtra("task_type",type);
            pi = PendingIntent.getService(context, 0, i, 0);
            iAlarmManager.set(AlarmManager.RTC_WAKEUP, TIME_DELAY, pi);
        }
    }
}